import 'dart:convert';
import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_base_library/app/utils/date_time_utils.dart';
import 'package:flutter_base_library/init/app_data.dart';
import 'package:get/get.dart';
import 'package:safe_manage/config/my_app_routes.dart';
import 'package:safe_manage/widgets/img_detail_page.dart';
import '../../../models/recordPicture.dart';

class AlarmPictureInfoController extends GetxController {
  var videoList = <String>[];
  late RecordPicture picture;
  String bumen = "";
  String imgUrl = "";
  @override
  void onInit() {
    super.onInit();
    picture = Get.arguments;
    Map p = Get.parameters;
    bumen = p["bumen"];
    if (picture.tpdz != null && picture.tpdz!.isNotEmpty) {
      imgUrl = AppData.instance.baseUrl! + picture.tpdz!;
    }
    String? spdz = picture.spdz;
    if (spdz != null && spdz.isNotEmpty) {
      var l = json.decode(spdz);
      if (l is List) {
        for (var element in l) {
          String baseUrl = AppData.instance.baseUrl!;
          List subStrs = baseUrl.split(":");
          if (subStrs.length >= 2) {
            baseUrl = subStrs[0] + ":" + subStrs[1];
          }
          videoList.add(
            baseUrl + element,
          );
        }
      }
    }
  }

  void showImgDetails(BuildContext context) {
    List<BrnBasicGroupConfig> allConfig = [
      BrnPhotoGroupConfig(
        configList: [
          BrnPhotoItemConfig(
            url: imgUrl,
            showBottom: true,
            bottomContentHeight: 20,
            // name: commonRecord.rwmc ?? "",
            name: "巡检类型：${picture.xjlx}",
            des: () {
              int? milliseSecond = picture.cjsj?.toInt();
              if (milliseSecond != null) {
                DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(
                  milliseSecond * 1000,
                );
                return "创建时间：${toLocalDateTimeByDateTime(dateTime)}";
              }
            }(),
          ),
        ],
      ),
    ];
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (BuildContext context) {
          return ImgDetailPage(
            allConfig: allConfig,
            themeData: BrnGalleryDetailConfig.light(),
          );
        },
      ),
    );
  }

  void videoClicked(int index) {
    // Get.toNamed(
    //   MyAppRoutes.alarmVideo,
    //   arguments: {
    //     "voideList": videoList,
    //     "index": index,
    //   },
    // );
    Get.toNamed(
      MyAppRoutes.fullVideo,
      arguments: videoList[index],
    );
  }
}
